#ifndef _SHARED_EVENT_SOURCE_H_
#define _SHARED_EVENT_SOURCE_H_

namespace Hiranipra {
	
	template<class E>
	class EventSource
	{
		typedef vector<EventHandler<E>*> EventHandlerList;
	public:

		void Add( EventHandler<E>* handler )
		{
			handler->Retain();
			_handlers.push_back( handler );
		}

		void Remove( EventHandler<E>* handler )
		{
			for( typename EventHandlerList::iterator it = _handlers.begin(); it != _handlers.end(); it++ )
			{
				if( *it == handler )
				{
					_handlers.erase( it );
					break;
				}
			}
			RELEASE( handler );
		}

		void Fire( const E& ev ) const
		{
			for( typename EventHandlerList::const_iterator it = _handlers.begin(); it != _handlers.end(); it++ )
				(*it)->HandleEvent( ev );
		}

	private:
		EventHandlerList	_handlers;
	};

}

#endif // _SHARED_EVENT_SOURCE_H_
